/*
 * Mixer.cpp
 *
 *  Created on: 2 gru 2013
 *      Author: dawid.wysakowicz
 */

#include "Mixer.hpp"
#include <boost/assert.hpp>
#include <algorithm>

mixer::Mixer::Mixer()
{
}

std::list<dna::genotypeSet> mixer::Mixer::combineGenotypes(
		dna::marker& marker)
{
	BOOST_ASSERT(marker.size() % 2 == 0);

	std::list<dna::genotypeSet > result;

	if (marker.size() == 0)
	{
		return result;
	}

	do
	{
		dna::genotypeSet collection;
		if (genGenotypes(marker, collection))
		{
			result.push_back(collection);
		}
	} while (next_permutation(marker.begin(), marker.end()));

	return result;
}

mixer::Mixer::~Mixer()
{
}

bool mixer::Mixer::genGenotypes(const dna::marker& allelsSet, dna::genotypeSet& collection)
{
	BOOST_ASSERT(allelsSet.size() % 2 == 0);
	for (dna::marker::const_iterator iter = allelsSet.begin();
			iter != allelsSet.end(); ++iter)
	{
		const dna::allel& first = *iter;
		const dna::allel& second = *(++iter);
		if (first > second)
		{
			collection.clear();
			return false;
		}
		collection.push_back(std::make_pair(first, second));
	}

	return true;
}
